package TileGUI;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
 
import javax.swing.ImageIcon;
 
public class Dude {
        private int x, y, width, height;
        public int nx2, nx;
        public int dx,dy;
        Image still;
        private ArrayList missiles;

        private boolean visible;

        private final int CRAFT_SIZE = 66;
 
        public Dude() {
                ImageIcon i = new ImageIcon("images/craft.png");
                still = i.getImage();
                nx2 = 685;
                x = 75;
                y = 172;

                width = still.getWidth(null);
                height = still.getHeight(null);

                nx = 0;
                missiles = new ArrayList();
                dx= 5;

        }
 
        public void move() {
                x = x + dx;
                y = y + dy;
                nx2 = nx2 + dx;
                nx = nx + dx;

                if(y > 320) y=320;
                if(y<-20) y= 0;

                
        }
 
        public int getX() {
                return x;
        }
 
        public int getY() {
                return y;
        }
 
        public Image getImage() {
                return still;
        }

        public ArrayList getMissiles() {
                return missiles;
        }
        public boolean isVisible() {
            return visible;
        }

        public void setVisible(boolean visible) {
            this.visible = visible;
        }

        public void fire() {
            if (missiles.size()<11)
                missiles.add(new Missile(75 + width, y + height/2));
        }

        public Rectangle getBounds() {
            return new Rectangle(75, y, width, height);
        }
 
        public void keyPressed(KeyEvent e) {
                int key = e.getKeyCode();
               /* if (key == KeyEvent.VK_LEFT)
                        dx = -1;*/
                if (key == KeyEvent.VK_SPACE) 
                    fire();

                if(key == KeyEvent.VK_UP)
            		dy =  -1;

                if(key == KeyEvent.VK_DOWN)
            		dy = 1;
                
        }
 
        public void keyReleased(KeyEvent e) {
                int key = e.getKeyCode();
 
               /* if (key == KeyEvent.VK_LEFT)
                        dx = 0;*/
 
              
                
                if(key == KeyEvent.VK_UP)
            		dy = 0;
       
                if(key == KeyEvent.VK_DOWN)
            		dy = 0;
            	
        }
 
}
	